Skip to content

test(widgets): add adversarial and map-bound Robolectric tests for ScaleBar - #1102

Open
dkhawk wants to merge 4 commits into
mainfrom
test/scalebar-adversarial-tests
Open

dkhawk wants to merge 4 commits into
mainfrom
test/scalebar-adversarial-tests

Conversation

@dkhawk

@dkhawk dkhawk commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1001 adding adversarial and live GoogleMap-bound Robolectric tests in ScaleBarAdversarialTest for :maps-compose-widgets.

What this tests

  • Geometry & edge cases (calculateDistance):
    • Antimeridian (±180°) crossing measures the short span (197 m) instead of wrapping the globe.
    • Strict-mock odd default width (65.dp → [468, 533], catching off-by-1 pixel truncation) and 3x display density scaling.
    • Zero (0.dp) and sub-pixel (1.dp at 0.5x density) widths return 0.
    • Continental zoom (zoom 2f, no Int overflow), near-polar latitude (85°), and monotonic zoom ordering (zoom 2 > 12 > 18 > 0).
  • Live GoogleMap + ScaleBar integration:
    • Real non-zero km/mi labels at zoom 12, reactive km/mi → m/ft transition at zoom 17, and ~50% distance decrease panning to 60° latitude.
    • Async projection transition (null → bound GoogleMap) replacing "0 ft" / "0 m" fallback without mutating cameraState.position.
    • measureAtCenter = true vs false divergence across a 600.dp viewport at zoom 3 (centerKm > topEdgeKm > 0).
  • DisappearingScaleBar timing & concurrency:
    • Rapid camera moves cancel the prior LaunchedEffect and extend visibility past the original deadline.
    • Camera move mid-exit-fade interrupts fade-out and recovers visibility cleanly.
    • visibilityDurationMillis = 0 safety and equal CameraPosition re-assignment not spuriously re-showing.

cc @kikoso @LoyalAbbas

* test(widgets): add JVM unit and composable tests for ScaleBar

* test(widgets): address review feedback in ScaleBarTest

- Assert calculateDistance against known ground-truth values (mocked equatorial span = 98m, plus Mercator zoom 12 checks at 0 deg and 60 deg latitude) instead of repeating the implementation formula.
- Remove unused sphericalDistance import from ScaleBarTest.
- Add displayed text assertions in ScaleBar test and mainClock-driven show/hide/re-show/hide assertions in DisappearingScaleBar test.
- Delete maps-compose-widgets/src/debug/AndroidManifest.xml and use testImplementation(libs.androidx.test.compose.ui.manifest).
- Remove unused androidx.test.core and kotlinx-coroutines-test dependencies from maps-compose-widgets/build.gradle.kts.
- Document null-projection fallback behavior in ScaleBarTest.
…aleBar

Adds ScaleBarAdversarialTest covering real failure modes beyond basic smoke checks:
- Antimeridian crossing (+/-180 deg) short-span measurement
- Strict-mock odd default width (65.dp) exact pixel span and 3x density scaling
- Zero and sub-pixel width handling, continental zoom overflow safety, near-polar latitude, and zoom monotonicity
- Live GoogleMap + ScaleBar integration verifying reactive updates on zoom, latitude pan, and null-to-bound projection transitions
- measureAtCenter = true vs false divergence across a viewport at low zoom
- DisappearingScaleBar rapid camera move timer cancellation/reset, mid-exit-fade interruption recovery, 0 ms duration, and equal-position idempotency
@dkhawk
dkhawk marked this pull request as ready for review December 2, 2026 15:33
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Coverage (unit tests)

Compared against 5a05472 on feature/robolectric-tests (#1099).

Module Line % Change Branch % Change
maps-compose 45.85% no change 15.28% no change
maps-compose-utils 26.29% no change 12.70% no change
maps-compose-widgets 72.90% 🔺 +69.03 57.14% 🔺 +57.14
TOTAL 42.60% 🔺 +3.65 16.18% 🔺 +1.92

Line and branch coverage from unit test reports. History is recorded on the coverage-history branch after each merge to feature/robolectric-tests.

@googlemaps-bot

Copy link
Copy Markdown
Contributor

Coverage (instrumentation tests)

Overall Project 46.22% 🍏

There is no coverage information present for the Files changed

Base automatically changed from feature/robolectric-tests to main December 2, 2026 16:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants